$(function() {

	// 链接url
	var baseUrl = "http://192.168.0.131/baichengwandianqingxiaowang/";
	// 是否到达底部
	var buttom = false;
	// 请求更多的数据
	$(document).on("swipeup",function(){
			var winH =$(window).height();
			var myScroll = $(window).scrollTop();
			if(($(document).height()<= winH||($('body').height() - myScroll) <= winH )&&!buttom){
				console.log("到底了");
				buttom=true;
				var hideJson = $("#hideJson").val();
				var jsonObject = JSON.parse(hideJson);
				var nextPage = $("#nextPage").val();
				var totalPage = $("#totalPage").val();
				jsonObject.pageNum = nextPage;
				if (Number(nextPage) <= Number(totalPage)) {// 如果当前页不是最后一页，则进行请求
					if(Number(totalPage)!=Number("1")){
						$(".slideToMore").hide();
						$(".loading").show();
						getMoreMsg(jsonObject);						
					}
				}else{
					$(".slideToMore").hide();
				}
			}
	})
	
	// 获得更多的数据
	function getMoreMsg(obj) {
		//成功回调函数
		var success = function(result) {
			
			if(result.code == 0 ){
				
				//获取数据
				var data = result.data;
	            //需要转换的字段
	            var createTime = "";
	            var type = "";
	            
	            //隐藏旋转框
	            $(".slideToMore").show();
				$(".loading").hide();
		
				//进行数据铺展
				for (var i = 0; i < data.length; i++) {		
					//对时间进行格式转换
					var createTime = formatTime(data[i].createTime, 0);
					//获取数据
						var str = '<div class="dumping block" id ="">'
					        +'<div class="item_container">'
					        +'<img class="item_img"  src="'+data[i].productSurfacePlot+'"/>'
					        +'<div class="info">'
					        +'<p class="name text-2">'+data[i].productName+'</p>'
					        +'<p class="num"><span>'+data[i].costQingxiaobiAmount+'</span>个</p>'
					        +'<p class="clearfloat other_block">'
					        +'<span class="">'+createTime+' </span>'
					        +'</p>'
					        +'</div>'
					        +'</div>'
					        +'</div>';					
					    //添加数据
					    $("#content").append(str);				    
				    //添加数据
				    $("#content").append(str);				
				}

				//对标志进行修改
				buttom = false;
				flag = false;

				// 如果不是最后一页，则对页数进行增加
				var nextPage = $("#nextPage").val();
				var totalPage = $("#totalPage").val();
				if (Number(nextPage) <= Number(totalPage)) {//TODO
					nextPage = Number(nextPage) + Number(1);
					$("#nextPage")[0].value = nextPage;
				}else{
					$(".slideToMore").hide();
				}	
			}else {
				tip.content(result.retMsg).show();
				$(".slideToMore").hide();
				$(".loading").hide();
			}

		}

		//失败回调函数
		var error = function() {
			$(".slideToMore").show();
			$(".loading").hide();	
			alert("请求失败");
			//对标志进行修改
			buttom = false;
			flag = false;
		}
		//进行请求
		var url = "/baichengwandianqingxiaowang/customer/findViewPriceByPage";
		var params = "jsonSearchCondition=" + JSON.stringify(obj);
		doAjax("POST", url, params, success, error, true, false);
	}

})

